class Solution {
public:
    vector<int> searchRange(vector<int>& nums, int target) {
        vector<int> res = { -1, -1 };
        if (nums.size() == 0) return res;

        int first = 0, end = 0;

        int l = 0, r = nums.size() - 1;
        while (l < r) {
            int mid = l + (r - l) / 2;
            if (nums[mid] > target) {
                r = mid;
            }
            else {
                l = mid + 1;
            }
        }
        end = l - 1;
        if (nums[end] != target) end = -1;


        l = 0, r = nums.size() - 1;
        while (l < r) {
            int mid = l + (r - l) / 2;
            if (nums[mid] >= target) {
                r = mid;
            }
            else {
                l = mid + 1;
            }
        }
        first = r;
        if (nums[first] != target)  first = -1;

        res = { first, end };

        return res;
    }
};